package com.hualian.ticket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualian.ticket.mapper.TicketMapper;
import com.hualian.ticket.pojo.Ticket;
import com.hualian.ticket.service.TicketService;
import com.hualian.ticket.util.JsonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 陈静
 * @date 2020/10/20 11:45
 */
@Service
public class TicketServiceImpl implements TicketService {
    @Resource
    TicketMapper ticketMapper = null;

    /**
     *  新建优惠券
     * @param ticket 目标对象 优惠券
     * @return 影响行数
     */
    @Override
    public Integer insertTicket(Ticket ticket) {
        return ticketMapper.insertSelective(ticket) ;
    }

    /**
     *  分页全查询
     * @param page 起始页
     * @return 分页数据
     */
    @Override
    public Map findAllByPage(Integer page) {
        //声明page
        PageHelper.startPage(page,2);
        //全查询
        List<Ticket> tickets = ticketMapper.selectAll();
        //将查询结果带到分页
        PageInfo<Ticket> info = new PageInfo<>(tickets);
        Map<String,Object> map = new HashMap<>();
        map.put("tickets",info.getList());
        map.put("total",info.getTotal());
        return map;
    }

    /**
     *  全查询优惠券
     * @return 优惠券列表
     */
    @Override
    public List<Ticket> findAll() {
        return ticketMapper.selectAll();
    }
}
